package cn.kgc.controller;

import cn.kgc.dao.GlExcelDao;
import cn.kgc.pojo.GlExcle;
import cn.kgc.pojo.PersonnelGl;
import cn.kgc.pojo.Pojo_hxy;
import cn.kgc.pojo.ResumeGl;
import cn.kgc.service.impl.GlServiceImpl;
import cn.kgc.util.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author:
 * @date: 2022/2/17
 * @description:
 */
@Controller
public class GlController {
    @Resource
    private GlServiceImpl glServiceImpl;

//    @RequestMapping("/职员明细表")
//    public String selall(Model model) {
//        List<PersonnelGl> list = glServiceImpl.selall();
//        System.out.println(list);
//        model.addAttribute("msg", list);
//        return "职员明细表";
//    }
    @RequestMapping("职员明细表")
    public String sel(){
        return "职员明细表";
    }

    @ResponseBody
    @RequestMapping("/showR")
    public String show(@RequestParam String department, @RequestParam String cname,
                       @RequestParam String status, @RequestParam Integer currentPage, @RequestParam Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        Page<PersonnelGl> list = glServiceImpl.selAllPersonnel(department, "%" + cname + "%", status);
        System.out.println(list);
        PageInfo<PersonnelGl> pageInfo = new PageInfo<PersonnelGl>(list);
        return JSON.toJSONStringWithDateFormat(pageInfo, "yyyy-MM-dd");
    }


    @RequestMapping("/储备人才统计表")
    public String showRe() {
        return "储备人才统计表";
    }

    @ResponseBody
    @RequestMapping("/showRe")
    public String showRe(@RequestParam String name, @RequestParam Integer currentPage, @RequestParam Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        Page<ResumeGl> list = glServiceImpl.selAllResume(name);
        System.out.println(list);
        PageInfo<ResumeGl> pageInfo = new PageInfo<ResumeGl>(list);
        return JSONObject.toJSONString(pageInfo);

    }

    @RequestMapping("/excelgl")
    public String excelgl(HttpServletRequest request, HttpServletResponse response) {
        List<GlExcle> selall = glServiceImpl.selall();

        try {

            ExcelUtil.export2Web(response,"职员明细表","职员明细表", GlExcle.class,selall);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
};
